<template>
  <div class="album w" ref="albumDom">
    <GlobalTitle title="新碟上架" />

    <!-- 骨架屏 -->
    <div class="content" v-if="newAlbumList.length === 0">
      <div class="content_item" v-for="item in 8" :key="item">
        <el-skeleton animated :throttle="500">
          <template slot="template">
            <el-skeleton-item
              variant="image"
              style="height: 224px; width: 224px"
            />
            <el-skeleton-item
              variant="p"
              style="height: 20px; width: 224px; margin: 10px 0"
            />
            <el-skeleton-item variant="p" style="height: 20px; width: 224px" />
          </template>
        </el-skeleton>
      </div>
    </div>

    <!-- 内容 -->
    <div class="content" v-else>
      <div class="content_item" v-for="item in newAlbumList" :key="item.id">
        <div class="content_item_img">
          <GlobalImageDeep
            :url="item.picUrl"
            :imgWidth="224"
            :imgHeight="224"
          />
          <!-- 播放按钮 -->
          <GlobalPlayMask
            :maskWidth="64"
            :maskHeight="64"
            @maskClick="toAlbumDetailsPage(item.id)"
          />
        </div>
        <p class="one_txt_cut" @click="toAlbumDetailsPage(item.id)">
          {{ item.name }}
        </p>
        <!-- <div class="one_txt_cut">{{ formatAuthor(item.artists) }}</div> -->
        <div class="one_txt_cut">
          <span
            v-for="e in item.artists"
            :key="e.id"
            @click="toSingerDetailsPage(e.id)"
            >{{ e.name }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 加载 观测 DOM 是否进入可视区的方法
import ObserverDomToScreen from "../../../../../utils/ObserverDomToScreen.js";
import { getNewAlbum } from "../../../../../api/homeApi";
export default {
  name: "album",
  components: {},
  data() {
    return {
      sssss:
        "https://cdnmusic.migu.cn/picture/2022/0106/1756/AMc3dc3a76db6d571d8f265044ac0a1319.jpg",
      newAlbumList: [],
    };
  },
  created() {},
  mounted() {
    // console.log(this.$refs.newSongs);
    ObserverDomToScreen(this.$refs.albumDom, this.getNewAlbum);
  },
  methods: {
    async getNewAlbum() {
      try {
        const result = await getNewAlbum();
        if (result.code === 200) {
          this.newAlbumList = result.albums;
          console.log("新碟上架 接口调用成功", this.newAlbumList);
        }
      } catch (error) {}
    },
    formatAuthor(artists) {
      let authors = "";
      artists.forEach((item) => {
        authors = authors + item.name + " / ";
        // console.log(authors);
      });
      return authors.slice(0, authors.length - 2);
    },
    toAlbumDetailsPage(id) {
      this.$router.push(`/albumDetails/${id}`);
    },
    toSingerDetailsPage(id) {
      this.$router.push(`/singerDetails/${id}`);
    },
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.album {
  /deep/ .el-image img {
    border-radius: 8px;
  }
  margin-top: 90px;
  .content {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .content_item {
      height: 316px;
      width: 288px;
      font-size: 14px;

      &:hover {
        /deep/ .playMask .play {
          display: block;
          cursor: pointer;
        }
      }

      .content_item_img {
        position: relative;
        width: 224px;
        height: 224px;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 30px;
          width: 100%;
          height: 100%;
          background: url("../../../../../assets/images/album-cover.png")
            no-repeat center;
        }
      }
      p {
        width: 224px;
        color: #333333;
        margin-top: 10px;
        margin-bottom: 10px;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
      div {
        width: 224px;
        display: block;
        color: #999999;
        span {
          margin-right: 4px;
        }
        span:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
